﻿using System.Diagnostics;
using VT.Framework.Designer.Flow;
using VT.Framework.Scene2D.Structs;
using static VT.Framework.Vision2D.VT2D.VTDetect;

namespace VIA.ImageProcessing
{
    public static class VTExtensions
    {
        public static VImage8Grey ToVImage8Grey(this ImageData image)
        {
            if (image == null) return null;
            return new VImage8Grey(image.Width, image.Height, image.Data.ToIntPtr())
            {
                XResolution = image.Resolution,
                YResolution = image.Resolution,
            };
        }
        public static VImage16Grey ToVImage16Grey(this ImageData3DU image)
        {
            if (image == null) return null;
            return new VImage16Grey(image.Width, image.Length, image.Data.ToIntPtr())
            {
                XResolution = image.XResolution,
                YResolution = image.YResolution,
                ZResolution = image.ZResolution
            };
        }
        public static VImage24Color ToVImage24Color(this ImageData image)
        {
            if (image == null) return null;
            return new VImage24Color(image.Width, image.Height, image.Data.ToIntPtr());
        }

        public static bool TryGetResult<T>(this VTFlowBlock block, string key, out T value)
        {
            value = default;
            if (block.Outputs.ContainsKey(key) && block.Outputs[key].Value != null)
            {
                value = (T)block.Outputs[key].Value;
                return true;
            }
            else
                return false;
        }


    }
}


